package com.zhu.service;


import com.zhu.mapper.UserMapper;
import com.zhu.mapper.WayMapper;

import com.zhu.pojo.Type;
import com.zhu.pojo.Way;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WayService {
    @Autowired
    private WayMapper wayMapper;
    @Autowired
    private UserMapper userMapper;

    public List<Way> wayList(String  username) {
        int userId= userMapper.getUserByName(username).getId(); //获取用户id
        return wayMapper.getAll(userId);
    }

    public Way get(int id) {
        Way way= wayMapper.getById(id);
        return way;
    }

    public boolean save(Way way) {
        System.out.println(way);
        int row = wayMapper.add(way);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }


    public boolean upd(Way way) {
        int row = wayMapper.update(way);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public boolean del(int  id) {
        int row = wayMapper.delete(id);
        if(row > 0) {
            return true;
        }else {
            return false;
        }
    }

    public List<Way> typeListByAdmin() {
        return wayMapper.getAllByAdmin();
    }
}
